package LeetCode.interview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import sun.tools.jar.resources.jar;
import util.LogUtils;

/*
 * 
原题　
	Implement the following operations of a stack using queues.
	
	push(x) -- Push element x onto stack.
	pop() -- Removes the element on top of the stack.
	top() -- Get the top element.
	empty() -- Return whether the stack is empty.
	Notes:
	You must use only standard operations of a queue -- which means only push to back, peek/pop from front, size, and is empty operations are valid.
	Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue.
	You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack).
		
题目大意
	使用队列实现栈操作 
	　　push(x) – 元素入栈 
	　　pop() – 元素出栈 
	　　top() – 取栈顶元素值 
	　　empty() – 判断栈是否为空 
	　　注意： 
	　　只能使用队列的标准操作，先进先出，求队列元素数，判断队列是否为空 
	　　由于编程语言原因，有些语言不支抚摩队列，可以使用链表或双向链表代替，但仅能使用标准的队列操作 
	　　你可以假设所有的操作都是合法的，即：当队列为空时不会有元素出栈和求栈顶元素的操作 
解题思路
	@My：使用LinkList.....(是不是有点过分了...)
 * @Date 2017-09-14 22：52
 */
public class _225_Implement_Stack_using_Queues {
	public static class ListNode {
		int val;
		ListNode next = null;
		ListNode(int x) {
			val = x;
		}
	}
	
	private LinkedList<Integer> mStack;
	
    /** Initialize your data structure here. */
    public _225_Implement_Stack_using_Queues() {
    	mStack = new LinkedList<Integer>();
    }
    
    /** Push element x onto stack. */
    public void push(int x) {
        mStack.addFirst(x);
    }
    
    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        if (!empty())
        	return mStack.removeFirst();
        return -1;
    }
    
    /** Get the top element. */
    public int top() {
        if (!empty())
        	return mStack.getFirst();
        return -1;
    }
    
    /** Returns whether the stack is empty. */
    public boolean empty() {
        if (mStack.size() > 0)	return false;
        return true;
    }
	public static void main(String[] args) {
		_225_Implement_Stack_using_Queues obj = new _225_Implement_Stack_using_Queues();
	
	}

}
